﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.Serialization;
using System.Security.Permissions;

using Model.Items.Weapons.Parts;

namespace Model.Items.Weapons
{
    //game data
    [Serializable]
    public class Sword : Weapon
    {
        //components
        private SwordHilt _SwordHilt;
        private SwordBlade _SwordBlade;

        protected Sword(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            if (info == null)
                throw new System.ArgumentNullException("info");
            swordHilt = info.GetValue("SwordHilt", typeof(SwordHilt)) as SwordHilt;
            swordBlade = info.GetValue("SwordBlade", typeof(SwordBlade)) as SwordBlade;
        }


        public Sword(SwordBlade swordblade, SwordHilt swordhilt)
        {
            swordHilt = swordhilt;
            swordBlade = swordblade;

            BaseName = swordblade.BaseName;            
        }

        public override String Name
        {
            get { return BaseName + " Sword"; }
        }

        public SwordHilt swordHilt
        {
            get { return _SwordHilt; }
            set
            {
                _SwordHilt = value;
                NotifyPropertyChanged("swordHilt");
            }
        }

        public SwordBlade swordBlade
        {
            get { return _SwordBlade; }
            set
            {
                _SwordBlade = value;
                NotifyPropertyChanged("swordBlade");
            }
        }

        public override int Aesthetic
        {
            get
            {
                return (int)(0.55 * (double)swordBlade.Aesthetic + 0.45 * (double)swordHilt.Aesthetic);
            }
        }

        public override int Quality
        {
            get
            {
                return (int)(0.80 * (double)swordBlade.Quality + 0.20 * (double)swordHilt.Quality);
            }
        }

        public override double MinPrice
        {
            get { return Price = swordBlade.Price + swordHilt.Price; }
        }

        public override string ToString()
        {
            return Name + "\n" + "Quality: " + Quality + "\nAesthetic: " + Aesthetic; ;
        }

        [SecurityPermission(SecurityAction.LinkDemand,
            Flags = SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(
        SerializationInfo info, StreamingContext context)
        {
            if (info == null)
                throw new System.ArgumentNullException("info");
            base.GetObjectData(info, context);
            info.AddValue("SwordHilt", swordHilt);
            info.AddValue("SwordBlade", swordBlade);
        }
    }
}
